
/**
** \file       ast_printrules.c
**
** \brief      this function parse the and_or rule
**
** \author     Ben M'rad Hanna, Laterem Hamza, Boillot Ulysse, De Olivera
**             Guillaume and Nguyen Viet Dung
**
** \version    1.0
**
** \date       28 Novembre 2010
**
*/

#include "ast_printer.h"

int	print_rulewhile(s_rulewhile	*node,
			int		i,
			int		fd,
			int		last)
{
  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"node while\"];\n", 25);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      ++i;
      if (node->in_while != NULL)
	last = print_cmpdlist(node->in_while, i, fd, last);
      if (node->in_do != NULL)
	last = print_dogroup(node->in_do, i, fd, last);
    }
  return (last);
}

int	print_rulefor(s_rulefor		*node,
		      int		i,
		      int		fd,
		      int		last)
{
  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"node while\"];\n", 25);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      ++i;
      if (node->in_in != NULL)
	print_word(node->in_in, i, fd);
      if (node->in_do != NULL)
	last = print_dogroup(node->in_do, i, fd, last);
    }
  return (last);
}

int	print_ruleif(s_ruleif		*node,
		     int		i,
		     int		fd,
		     int		last)
{
  if (node != NULL)
    {
        ++last;
	print_int(last, fd);
	write(fd, " [label = \"node if\"];\n", 22);
	print_int(i, fd);
	write(fd, " -> ", 4);
	print_int(last, fd);
	write(fd, "\n", 1);
	++i;
	if (node->in_if != NULL)
	  last = print_cmpdlist(node->in_if, i, fd, last);
	if (node->in_then != NULL)
	  last = print_cmpdlist(node->in_then, i, fd, last);
	if (node->else_clause != NULL)
	  last = print_else_clause(node->else_clause, last, fd);
    }
  return (last);
}

int	print_ruleuntil(s_ruleuntil	*node,
			int		last,
			int		fd)
{
  int	i = last;

  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"node while\"];\n", 25);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      ++i;
      if (node->in_until != NULL)
	last = print_cmpdlist(node->in_until, i, fd, last);
      if (node->in_do != NULL)
	last = print_dogroup(node->in_do, i, fd, last);
    }
  return (last);
}

int	print_rulecase(s_rulecase	*node,
		       int		last,
		       int		fd)
{
  int	i = last;

  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"node while\"];\n", 25);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      ++i;
      if (node->in_in != NULL)
	print_caseclause(node->in_in, i, fd);
    }
  return (last);
}
